package com.atguigu.day17.test03;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;

/**
 * @author fenge
 */
public class Test03 {
    public static void main(String[] args) {
        System.out.print("10个随机值:");
        ArrayList<Integer> arrayList = new ArrayList<>();
        ArrayList<Integer> arrayListsrc = new ArrayList<>();
        for (int i = 0; i < 10; ) {
            int rand = (int) (Math.random() * 100) + 1;
            arrayListsrc.add(rand);
            arrayList.add(rand);//0,50 100-1+1+1
            i++;

        }
        Iterator iterator = arrayList.iterator();
        for (Integer integer : arrayList) {
            System.out.print(iterator.next().toString()+",");
        }
        ArrayList max = new ArrayList();
        arrayList.sort(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return -(o1-o2);
            }
        });
        System.out.println();

        Iterator iterator2 = arrayList.iterator();
        for (Integer integer : arrayList) {
            System.out.print(iterator2.next().toString()+",");
        }
        ArrayList<Integer> arrayList1 = new ArrayList<>();
        {
            Integer temp = arrayList.remove(0);
            arrayList1.add(temp);
            arrayListsrc.remove(arrayListsrc.indexOf(temp));
        }{
            Integer temp = arrayList.remove(0);
            arrayList1.add(temp);
            arrayListsrc.remove(arrayListsrc.indexOf(temp));
        }{
            Integer temp = arrayList.remove(0);
            arrayList1.add(temp);
            arrayListsrc.remove(arrayListsrc.indexOf(temp));
        }
//        arrayListsrc.remove(arrayListsrc.indexOf(arrayList1.add(arrayList.remove(0))));
//        arrayListsrc.remove(arrayListsrc.indexOf(arrayList1.add(arrayList.remove(0))));
//        arrayListsrc.remove(arrayListsrc.indexOf(arrayList1.add(arrayList.remove(0))));
//        arrayList1.add(arrayList.remove(0));
//        arrayList1.add(arrayList.remove(0));
//        arrayList1.add(arrayList.remove(0));
        System.out.print("\n前3个最大的:");
        Iterator iterator4 = arrayList1.iterator();
        for (Integer integer : arrayList1) {
            System.out.print(iterator4.next().toString()+",");
        }
        System.out.println("\n删除后:");
//        Iterator iterator3 = arrayList.iterator();
//        for (Integer integer : arrayList) {
//            System.out.print(iterator3.next().toString()+",");
//        }
        Iterator iterator5 = arrayListsrc.iterator();
        for (Integer integer : arrayListsrc) {
            System.out.print(iterator5.next().toString()+",");
        }
//        arrayList.remove(0)));
//        arrayListsrc.remove(arrayListsrc.indexOf(arrayList.remove(0)));
//        arrayListsrc.remove(arrayListsrc.indexOf(arrayList.remove(0)));
    }
}
